home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / macgzip_022-src / macos / Posix / ThinkCPosix Sources / access.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-26  |  835 b   |  43 lines  |  [TEXT/MPS ]

  1. /* $Id: access.c,v 1.1 1992/09/14 14:27:36 TimothyMurphy Exp TimothyMurphy $ */
  2.  
  3. #include "ThinkCPosix.h"
  4.  
  5. /*
  6.  * If mode includes check for write permission,
  7.  * and file is locked, return -1 (failure).
  8.  */
  9.  
  10. #define LOCKBIT 0x1
  11.  
  12. int
  13. access(path, mode)
  14.     char *path;
  15.     int mode;    /* ignored */
  16. {
  17.     CInfoPBRec cipbr;
  18.     HFileInfo *fpb = (HFileInfo*)&cipbr;
  19.     DirInfo *dpb = (DirInfo*)&cipbr;
  20.     short err;
  21.     char name[FILENAME_MAX];
  22.     
  23.     strncpy(name, path, sizeof(name)-1);
  24.     c2pstr(name);
  25.     dpb->ioDrDirID= 0L;
  26.     fpb->ioNamePtr= (unsigned char*)name;
  27.     fpb->ioVRefNum= 0;
  28.     fpb->ioFDirIndex= 0;
  29.     fpb->ioFVersNum= 0;
  30.     err= PBGetCatInfo(&cipbr, FALSE);
  31.     if (err != noErr) {
  32.         errno = ENOENT;
  33.         return -1;
  34.     }
  35.     /* check for write-permission = not locked */
  36.     if ((mode & 02) && (fpb->ioFlAttrib & LOCKBIT)) {
  37.         errno = EACCES;
  38.         return -1;
  39.     }
  40.     return 0;
  41. }
  42.  
  43.